import { onBeforeMount, computed, unref, inject } from 'vue'
import { useWebsiteStore } from '@/store/websites'
import { keywordsKey, KeywordsModal } from '@/keys'

// 显示和删除列表信息
export const useList = () => {
  const websiteStore = useWebsiteStore()

  const list = computed(() => {
    const kw = inject<typeof KeywordsModal>(keywordsKey)
    const keywords = unref(kw.keywords) || ''
    // console.log(keywords)
    return websiteStore.find(keywords)
  })

  onBeforeMount(() => {
    websiteStore.init()
  })
  
  const deleteItem = (id: string) => {
    websiteStore.deleteItem(id)
  }

  return {
    list,
    deleteItem
  }
}